﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MLRobotic.Tower.Common;

namespace MLRobotic.Tower.Forms
{
    public partial class ConfigurationControl : UserControl
    {
        private Config _config { get; set; }
        private bool _suspendUpdates = false;

        public ConfigurationControl(Config config)
        {
            _config = config;
            InitializeComponent();
            Config2Display();
        }

        private void Config2Display()
        {
            if (_config == null)
                return;

            try
            {
                _suspendUpdates = true;

                if (_config.Team == Team.Blue)
                    radioTeamBlue.Checked = true;
                else
                    radioTeamRed.Checked = true;

                if (_config.Lens == Lens.FishEye)
                    radioObjFishEye.Checked = true;
                else if (_config.Lens == Lens.Wide)
                    radioObjWide.Checked = true;
                else
                    radioObjStandard.Checked = true;

                if (_config.Phone == Phone.TouchPro2)
                    radioPhoneTouchPro2.Checked = true;
                else
                    radioPhoneTouch.Checked = true;

                if (_config.Master)
                    radioRoleMaster.Checked = true;
                else
                    radioRoleSlave.Checked = true;
            }
            finally
            {
                _suspendUpdates = false;
            }
        }

        private void Display2Config()
        {
            if (_config == null || _suspendUpdates)
                return;

            if (radioTeamBlue.Checked)
                _config.Team = Team.Blue;
            else
                _config.Team = Team.Red;

            if (radioObjFishEye.Checked)
                _config.Lens = Lens.FishEye;
            else if (radioObjWide.Checked)
                _config.Lens = Lens.Wide;
            else
                _config.Lens = Lens.Standard;

            //if (radioPhoneTouchPro2.Checked)
            //    _config.Phone = Phone.TouchPro2;
            //else
            //    _config.Phone = Phone.Touch;

            _config.Master = radioRoleMaster.Checked;
        }

        private void anyControl_ValueChanged(object sender, EventArgs e)
        {
            Display2Config();
        }
    }
}